from pylab import *
from PyQt4.Qt import *
import matplotlib
import numpy


dx = 2.
dy = 2.
dt = 0.001
#f1 = open('D:/1/200808_143414_K1.txt', 'r')
#f2 = open('D:/1/200808_143414_K2.txt', 'r')
#f3 = open('D:/1/200808_143414_K3.txt', 'r')
#f4 = open('D:/1/200808_143414_K4.txt', 'r')

f1 = open('/home/gandhi/Dropbox/Magnetometer/Data/mpm001_4K/190808_150137_K1.txt', 'r')
f2 = open('/home/gandhi/Dropbox/Magnetometer/Data/mpm001_4K/190808_150137_K2.txt', 'r')
f3 = open('/home/gandhi/Dropbox/Magnetometer/Data/mpm001_4K/190808_150137_K3.txt', 'r')
f4 = open('/home/gandhi/Dropbox/Magnetometer/Data/mpm001_4K/190808_150137_K4.txt', 'r')

k1 = loadtxt(f1)
k2 = loadtxt(f2)
k3 = loadtxt(f3)
k4 = loadtxt(f4)

#k1 = zeros(1000)
#k2 = zeros(1000)
#k3 = zeros(1000)
#k4 = ones(1000)

k1 = k1-k1[:1]
k2 = k2-k2[:1]
k3 = k3-k3[:1]
k4 = k4-k4[:1]

x = arange(1, dx+1, 1)
y = arange(1, dy+1, 1)
yy = y.reshape(dy, 1)
S1 = ((dx-x)*(dy-yy))
S1 = S1.reshape(S1.size, 1)
S2 = x*(dy-yy)
S2 = S2.reshape(S2.size, 1)
S3 = x*yy
S3 = S3.reshape(S3.size, 1)
S4 = (dx-x)*yy
S4 = S4.reshape(S4.size, 1)
#S = vstack([S1, S2, S3, S4])
#K = vstack([k1, k2, k3, k4])
B1 = k1 * S1
B1 = B1.reshape(B1.size, 1)
B2 = k2 * S2
B2 = B2.reshape(B2.size, 1)
B3 = k3 * S3
B3 = B3.reshape(B3.size, 1)
B4 = k4 * S4
B4 = B4.reshape(B4.size, 1)
Bxy = (B1 + B2 + B3 + B4)/4


ion()
hold(False)
B = resize(Bxy, (4, 1000))



dt = 0.001
#NFFT = 1024
fs = 1.0/dt

Fvz = 1000
Tzv = 1./Fvz
#ff = rfft(k4)
#r = arange(1,  len(ff), 1)
#plot(r, abs(ff[1:1000]))



#Pxx, freqs, bins, im = specgram(k1, NFFT=NFFT,  Fs=Fs)

#obr = resize(B[:,0], (10, 10))

#imshow(obr,  interpolation='bicubic')
#obr = resize(B[:,1], (100, 100))
#figimage(obr, 100, 100)

#colorbar()
#show()
for i in range(0, 999):
    obr = resize(B[:,i], (2, 2))
    im = imshow(obr,  interpolation='bicubic', animated=True)
    #im = figimage(obr, 100, 100)
    im.set_data(obr)


show()



#print Pxx

#plot(bins)
show()


f1.close()
f2.close()
f3.close()
f4.close()
